<?php

namespace app\admin\model\user;

use think\Model;


class Extend extends Model
{

    

    

    // 表名
    protected $name = 'user_extend';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'accept_sms_text',
        'is_realname_text'
    ];
    

    
    public function getAcceptSmsList()
    {
        return ['0' => __('Accept_sms 0'), '1' => __('Accept_sms 1')];
    }


    public function getAcceptSmsTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['accept_sms']) ? $data['accept_sms'] : '');
        $list = $this->getAcceptSmsList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIsRealnameList()
    {
        return ['0' => '未实名', '1' => '已实名'];
    }


    public function getIsRealnameTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_realname']) ? $data['is_realname'] : '');
        $list = $this->getIsRealnameList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user()
    {
        return $this->belongsTo('\\app\\admin\\model\\User', 'user_id', 'id')->setEagerlyType(0);
    }

    public function cards()
    {
        return $this->hasMany('\\app\\admin\\model\\user\\Card', 'user_id', 'user_id');
    }


}
